package de.syfy.project.game;

import de.syfy.project.engine.errors.NoSuchAnimationException;
import de.syfy.project.game.base.Character;
import de.syfy.project.engine.Sprite;
import de.syfy.project.engine.interfaces.Game;
import java.awt.geom.Point2D;
import java.util.Random;

    /**
     * Alle Fertigkeiten-abfragen etc laufen über diese Klasse
     * wenn also das Model getroffen wird (pixel genaue Kollision) wird
     * über diese Variable gehandelt => 
     * 
     * 
     * Kollision wird dann in doLogic gemacht :)
     * 
     * 
     * Andersrum führt das Modell aktionen aus und holt sich die passenden Werte
     * aus seinem Character.
     *
     */ 
public class CharacterModel extends Sprite{

    @Override
    public void onDeath() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    public static enum Direction {NORD , SUED , OST , WEST}
    /**
     * Position des Charakters
     */
    Point2D.Float pos = new Point2D.Float(); 

    /**
     * Charakterwerte, ausrüstung und generell 
     * alles was einen Charakter ausmacht
     */
    Character charakter;
    
    Direction face = Direction.SUED;
    
    public CharacterModel(Game game){
        //Konstruktor muss noch richtig implimentiert werden
        super(game);
        this.charakter = new Character(this);
    }
    /**
     * Liefert den Character
     * @return 
     */
    public Character getCharacter(){
        return this.charakter;
    }

    @Override
    public void setPosition(Point2D.Float p) {
        this.pos.x = p.x;
        this.pos.y = p.y;
    }

    @Override
    public Point2D.Float getPosition() {
        return pos;
    }

    @Override
    public void playAnimation(String name) {
        try {
            super.playAnimation(name);
        } catch (NoSuchAnimationException ex) {
            System.out.println("playAnimation error");
        }
    }

    @Override
    public void setNext() {
        super.setNext();
    }

    @Override
    public void onClick() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void onHover() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    
    @Override
    public void doLogic(long delta){
        super.doLogic(delta);
        
    }
    
    public Direction getFace() {
        return face;
    }

    public void getHit(int dmg){
        Random r = new Random();
        if(this.charakter.getCharValue().getAvoid() < r.nextFloat()){
            this.charakter.getCharValue().setHp(this.charakter.getCharValue().getHp() - dmg);
        }
        System.out.println("AUA!!!");
        System.out.println("HP: "+charakter.getCharValue().getHp());
        
    }
    
    public boolean lebendig(){
        return this.charakter.getCharValue().getHp() > 0;
    }
}